﻿using IBMU2.UODOTNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mvLibrary.Helpers.UniverseConector
{
    public class Connector
    {
        public const string ACCOUNT = "USUARIOS";
        public const int WRONG_LOGIN_ERROR_CODE = 80011;
        public UniSession Connect(string userId, string password)
        {

            UniSession uniSession;
            try
            {
                uniSession = UniObjects.OpenSession("UNIVERSE", userId, password, ACCOUNT);
            }
            catch (UniSessionException ex)
            {
                try
                {
                    uniSession = ex.ErrorCode.Equals(WRONG_LOGIN_ERROR_CODE) ? null : uniSession = UniObjects.OpenSession("90.0.0.102", userId, password, ACCOUNT);
                }
                catch (UniSessionException)
                {
                    uniSession =  null;
                }
            }

            return uniSession;
        }
    }
}
